home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_5.lha / 8_5 / fread.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  729b  |  35 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / read in num objects of the given size into the buffer
  6. nt fread(void *vbuf, unsigned int size,
  7.    unsigned int num, FILE *f)
  8.  
  9.    char *buf = (char*)vbuf;
  10.    if (f->mode == input)
  11. {
  12. // read in num * size bytes
  13. for (unsigned int n = num; n-- > 0; )
  14.     for (unsigned int s = size; s-- > 0; )
  15.     {
  16.     char c;
  17.     if (f->in->get(c))
  18.         *buf++ = c;
  19.  
  20.     else
  21.         // The end of the input
  22.         // partway through an object.
  23.         // Return the number of complete
  24.         // objects read so far.
  25.         return num - n;
  26.     }
  27.  
  28. // Return the number of
  29. // complete objects read.
  30. return num - n;
  31. }
  32.  
  33.    return 0;
  34.  
  35.